﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sern.Common
{
    public class DynamicDisposable : IDisposable
    {
        private Action _disposingAction;

        private DynamicDisposable(Action disposingAction)
        {
            _disposingAction = disposingAction;
        }


        void IDisposable.Dispose()
        {
            _disposingAction();
        }

        public static IDisposable CreateFrom(Action disposingAction)
        {
            return new DynamicDisposable(disposingAction);
        }
    }
}
